package net.trade.trade.service;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.HashMap;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.tomcat.jni.Time;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath*:resources/applicationContext*.xml")
public class TradeServiceImplTest extends AbstractJUnit4SpringContextTests{

	@Autowired
	private ITradeService service;
	
	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testGetMarket() {
		fail("Not yet implemented");
	}

	@Test
	public void testTradeMY() {
		fail("Not yet implemented");
	}
	
	@Test
	public void testTsaleMY(){
		// 买
		HashMap map = new HashMap();
		map.put("user", "12");
		map.put("blType", "1");
		map.put("blNum", "2");
		map.put("blDirect", "1");
		map.put("blPoint", "4125");
		service.tradeMY(map);
		// 卖
		map.put("blType", "2");
		map.put("busiid", "9");
		map.put("blPoint", "4115");
		service.tradeMY(map);
	}
	
	@Test
	public void testGetUserOrder(){
		List<HashMap> list =service.getUserOrder("12");
		for(HashMap map:list){
//			JSONObject obj = new JSONObject();
			System.out.println(map.toString());
			JSONObject obj = JSONObject.fromObject(map);
			System.out.println(obj);
		}
//		String s = JSONArray.fromObject(map).toString();
//		System.out.println(s);
	}

	@Test
	public void testIsOverflow() {
		HashMap map = new HashMap();
		map.put("user", "12");
		map.put("buy_num", "51");
		boolean bool = service.isOverflow(map);
		assertFalse(bool);
		
		map.put("buy_num", "10");
		bool = service.isOverflow(map);
		assertTrue(bool);
	}

}
